/*
 * File Name : command_factory.cpp
 * Auther : dream.liuguobiao
 * Create Date : 2010-5-14
 * Last Edit : 2010-5-16
 */

#include <string>

#include "command_factory.h"
#include "command.h"

#include "ls.h"
#include "my_exit.h"
#include "halt.h"
#include "cd.h"
#include "su.h"
#include "mkdir.h"
#include "rmdir.h"

#include "my_string.h"

command_factory *command_factory::instance_command_factory = NULL;

command_factory::command_factory()
{
}

command_factory *command_factory::get_command_factory()
{
  if( NULL == instance_command_factory)
    instance_command_factory = new command_factory();
  return instance_command_factory;
}

command *command_factory::get_command( std::string *command_name )
{
  command *current_command;
  my_string *MyString = my_string::get_my_string();
  std::string *sub_string = MyString->get_sub_string( *command_name );
  if( (std::string)"ls" == *sub_string ) current_command = new ls(command_name);
  else if( (std::string)"exit" == *sub_string ) current_command = new my_exit(command_name);
  else if( (std::string)"halt" == *sub_string ) current_command = new halt(command_name);
  else if( (std::string)"cd" == *sub_string ) current_command = new cd(command_name);
  else if( (std::string)"su" == *sub_string ) current_command = new su(command_name);
  else if( (std::string)"mkdir" == *sub_string ) current_command = new mkdir(command_name);
  else if( (std::string)"rmdir" == *sub_string ) current_command = new my_rmdir(command_name);
  else current_command = NULL ;
  return current_command;
}

